package uk.co.javahelp.sender.message;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Message {
	private final String to;
	
	private final String cc;
	
	private final String template;
	
	private final Map<String, Object> attributes = new HashMap<String, Object>();
	
	private final List<Attachment> attachmentList = new ArrayList<Attachment>();

	public Message(final String to, final String template) {
		this(to, null, template);
	}
	public Message(final String to, final String cc, final String template) {
		this.to = to;
		this.template = template;
		this.cc = cc;
	}

	public String getTo() {
		return to;
	}

	public String getCc() {
		return cc;
	}

	public String getTemplate() {
		return template;
	}

	public Map<String, Object> getAttributes() {
		return attributes;
	}

	public List<Attachment> getAttachmentList() {
		return attachmentList;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((to == null) ? 0 : to.hashCode());
		result = prime * result + ((template == null) ? 0 : template.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object object) {
		if (this == object) return true;
		if (object == null) return false;
		if (this.getClass() != object.getClass()) return false;
		
		final Message that = (Message) object;
		if (this.to == null) {
			if (that.to != null)
				return false;
		} else if (!this.to.equals(that.to))
			return false;
		
		if (this.template == null) {
			if (that.template != null)
				return false;
		} else if (!this.template.equals(that.template))
			return false;
		
		return true;
	}

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();
		sb.append("Template: ");
		sb.append(template);
		sb.append(" To: ");
		sb.append(to);
		return sb.toString();
	}
}
